limsSamplecodeGenerate.editPage = {

    getGridParam: function () {
        var _this = this;
        return {
            type: 'grid',
            id: 'lims-samplecode-generate-edit-list-grid',
            url: limsSamplecodeGenerate.baseUrl + '/queries',
            service: 'limsSamplecodeGenerateServiceImpl',
            dbTable: 'T_LIMS_SAMPLECODE_GENERATE',
            columns: limsSamplecodeGenerate.getEditListColumns(),
            onLoadSuccess: function (data) {
                if (!Gikam.isEmpty(data)) {
                    this.activeRowByIndex(0);
                } else {
                    Gikam.cleanCompData(['lims-samplecode-generate-edit-list-base-info-form']);
                }
            },
            onRowActive: function (index, row) {
                Gikam.getAsyncComp('lims-samplecode-generate-record-edit-list-grid').done(function (grid) {
                    grid.refresh({
                        url: limsSamplecodeGenerate.baseRecordUrl + '/queries',
                        requestData: {
                            generateId_EQ: row.id
                        }
                    })
                })
            },
            deleteFormatter: function (row) {
                return row.generateBatchCode
            },
            page: true,
            toolbar: [{
                type: 'button',
                text: 'GIKAM.BUTTON.INSERT',
                icon: 'add',
                onClick: function () {
                    Gikam.preInsert({
                        modalTitle: 'BASELINE.SAMPLEMANAGE.SAMPLECODEGENERATES.MODAL.ADD',
                        fields: limsSamplecodeGenerate.getBaseInfoFormFields(),
                        url: limsSamplecodeGenerate.baseUrl,
                        titleWidth: 120
                    }).done(function (id) {
                        Gikam.getComp('lims-samplecode-generate-edit-list-grid').refresh()
                    })
                }
            }]
        }
    },

    getRecordGridParam: function () {
        var _this = this;
        return {
            type: 'grid',
            id: 'lims-samplecode-generate-record-edit-list-grid',
            // url: limsSamplecodeGenerate.baseRecordUrl + '/queries',
            service: 'limsSamplecodeGenerateRecordServiceImpl',
            dbTable: 'T_LIMS_SAMPLECODE_GENERATE_RECORD',
            columns: limsSamplecodeGenerate.getRecordEditListColumns(),
            order: {
                generateSampleCode: 'asc'
            },
            onLoadSuccess: function (data) {
                if (!Gikam.isEmpty(data)) {
                    this.activeRowByIndex(0);
                } else {
                }
            },
            onRowActive: function (index, row) {
            },
            page: true,
            toolbar: [{
                type: 'button',
                text: '标签打印',
                icon: 'label-print',
                onClick: function () {
                    var selections = Gikam.getComp('lims-samplecode-generate-record-edit-list-grid').getSelections()
                    if (Gikam.isEmpty(selections)) {
                        Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM')
                        return
                    }
                    let url = limsSamplecodeGenerate.baseRecordUrl + '/print'
                    workspace.window.showMask()
                    Gikam.postText(url, Gikam.getJsonWrapper(null, [null, selections])).done(function (fileId) {
                        Gikam.openFile(fileId, false)
                    }).always(function () {
                        workspace.window.closeMask()
                    })
                }
            }]
        }
    },

    create: function () {
        var _this = this;
        Gikam.create('layout', {
            id: 'lims-samplecode-generate-edit-list-layout',
            renderTo: workspace.window.$dom,
            west: {
                width: '50%',
                items: [this.getGridParam()]
            },
            center: {
                items: [this.getRecordGridParam()]
            }
        });
    },

    init: function () {
        this.create();
    }
};
